#!/bin/csh -f
set t=(2200 2100 2000 1900 1800 1700 1600 1500 1400 1300 1200 1100 1000 900 800 700 600 500 400 300 200 100)
set norm=
set tmname=TM
while ("$1" != "")
    switch ($1)
	case -h:
	    echo "Synopsis: tmdia [TMname] [[-t T0,dT,NT ] [-a]]"
	    exit
	breaksw
	case -tm:
	    shift
	    set tmname=$1
	breaksw
	case -a:
	    if(-f nat.M) then
		set norm=`awk '{print $1}' nat.M`
	    endif
	breaksw
	case -t: #-temps T0,dT,NT
	    shift
	    set t=(`awk 'BEGIN{split(ARGV[1],a,",");for(i=1;i<=a[3];i++){printf("%i ",a[1]+(i-1)*a[2])};exit}' $1`)
	breaksw
	default:
	    set tmname=$1
	    if(! -f $tmname) then
		echo "transfer matrix $tmname does not exist here"
		exit
	    endif
	breaksw
    endsw
    shift
end
if($norm == "" && ! -f th.inp) then
    echo "need th.inp"
    exit
endif
if(! -f TM) then
    echo "need TM"
    exit
endif
if($norm == "") then
    set norm=`awk 'FNR>1&&$(NF)~"M"{print $1+$2+$3;exit}' th.inp`
endif
(echo $norm ; cat $tmname ; echo $t | awk '{gsub(/ /,"\n");print $0}') | tmdia_
##
